package com.saozhu.utils;

import java.io.InputStream;
import java.util.Random;
import java.util.Scanner;

public class Console {

	private static Scanner scanner;
	
	static {scanner = new Scanner(System.in);}
	
	private Console(InputStream is){
		scanner = new Scanner(is);
	}
	
	public static String NEW_LINE = "\n";
	
	public static void print(String line){
		System.out.print(line);
	}
	
	public static void println(String line){
		System.out.println(line);
	}
	
	public static void println(Object object){
		System.out.println(object);
	}
	
	public static void teminate() {
		
		System.out.println("bye-bye");
		System.exit(0);

		
	}
	
	public static String askUserInput(String prompt){		
		while(true) {
			System.out.print(prompt+">");
			String input = scanner.nextLine().trim();
			if(!"".equals(input)) {
				return input;
			}
			System.out.println("Invalid input,Empty value is not allowed!");
		}
		
	}
	
	public static int setInput(String prompt){		
		while(true) {
			System.out.print(prompt+">");
			try{
			int input = Integer.parseInt(scanner.nextLine());			
				if(input<20&&input>0) {
					return input;
				}
			}catch(NumberFormatException e) {
				System.out.println("Invalid input, value is allowed in (0-20)!");
			}			
		}
		
	}
	
	public static int randomNum() {
		Random random = new Random();
		return random.nextInt(100000)+100000;
	}
	
}
